package com.kang.commons.util;

import com.alibaba.fastjson.JSONObject;
import com.kang.bean.AccessToken;
import lombok.extern.slf4j.Slf4j;

/**
 * @program: service
 * @description: token解析类，用以获取登录的信息
 * @author: K.faWu
 * @create: 2022-03-07 15:59
 **/
@Slf4j
public class TokenUtil {

    public static Long getUserIdToToken(String token){
        String tokenJson = EncryptUtil.decrypt(token);
        AccessToken accessToken = JSONObject.parseObject(tokenJson, AccessToken.class);
        //判断是否过期
        if(System.currentTimeMillis() - accessToken.getExpire() > 0){
            log.warn("{}认证信息过期，请重新登录！",accessToken.getUserId());
            return -1L;
        }else{
            return accessToken.getUserId();
        }
    }
}
